package cn.wolfcode.p2p.mgrsite.controller;

import cn.wolfcode.p2p.base.domain.LoginInfo;
import cn.wolfcode.p2p.base.excetion.DisplayableExcetion;
import cn.wolfcode.p2p.base.service.ILofinInfoService;
import cn.wolfcode.p2p.base.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LoginController {

    @Autowired
    private ILofinInfoService infoService;

    //管理人员登录
    @RequestMapping("/mgrLogin")
    @ResponseBody
    public Object mgrLogin(String username, String password) {
        AjaxResult result = null;
        try {
            LoginInfo info = infoService.userLogin(username, password, LoginInfo.USERTYPE_MANAGER);
            if (info == null) {
                result =new AjaxResult(false,"账号或者密码错误");
                return result;
            }
            result = new AjaxResult();
        } catch (DisplayableExcetion e) {
            e.printStackTrace();
            result = new AjaxResult(false, e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            result = new AjaxResult(false,"系统出错,请联系管理员");
        }
        return result;
    }

    @RequestMapping("/main")
    public String mainPage( ) {
        return "/main";
    }


}
